import { SysMenuDao } from "@common/dao/sys_menu.dao";
import { SysUserRoleDao } from "@common/dao/sys_user_role.dao";


export const SysPermissionService = {
    // 获取用户权限
    getUserPermissions:async (user_id: number | string) => {
        const userId = Number(user_id);
        if (userId === 1) {
            return ['*:*:*'];
        }else{
            let permissions: string[] = [];
            let roleIds = await SysUserRoleDao.getUserRoleIds(userId);
            if (roleIds.length > 0) {
                let rolePermissions = await SysMenuDao.getRolePermissions(roleIds[0]);
                permissions = [...permissions, ...rolePermissions];
            }
            // 去重
            permissions = [...new Set(permissions)];    
            console.log(permissions);
            // 排序
            permissions.sort();
            return permissions;
        }
    }
}
